package com.example.mycat.service;

import com.example.mycat.model.User;
import com.example.mycat.respository.UserRespository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 用户业务层
 */
@Service
public class UserService {

    private static final Logger log = LoggerFactory.getLogger(UserService.class);

    /**
     * 业务层要去掉持久层
     */
    @Autowired
    private UserRespository userRespository;


    /**
     * 保存用户
     * @param user
     * @return
     */
    public User saveUser(User user){
        try{
            //业务层要去掉持久层的添加的方法，也就是JPA里的东西
            User save = userRespository.save(user);
            if (save != null){
                return save;
            }else {
                return null;
            }
        }catch (Exception e){
            e.printStackTrace();
            log.error(UserService.class.getName()+"save user is error");
            return null;
        }
    }




}
